﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WorkbenchTest
{
    public delegate List<object> FillDatabaseHandler();

    public partial class SelectorForm : Form
    {
        public event FillDatabaseHandler FillDatabase;
        string firstMessage;

        public object SelectedItem
        {
            get
            {
                return comboBox1.SelectedItem;
            }
        }

        public SelectorForm()
        {
            InitializeComponent();
        }

        public SelectorForm(string title, string firstMessage)
        {
            InitializeComponent();
            this.Text = title;
            this.firstMessage = firstMessage;
        }

        void fillList()
        {
            comboBox1.Items.Clear();
            comboBox1.Items.Add(firstMessage);

            if (FillDatabase != null)
                comboBox1.Items.AddRange(FillDatabase().ToArray());
            comboBox1.SelectedIndex = 0;
        }

        private void SelectorForm_Load(object sender, EventArgs e)
        {
            fillList();
        }

        private void buttonSelect_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.OK;
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
        }

        private void buttonRefresh_Click(object sender, EventArgs e)
        {
            fillList();
        }
    }
}
